package com.itjcloud.iot.gateway.tools;


import reactor.core.publisher.Mono;

import static org.springframework.security.oauth2.core.OAuth2AccessToken.TokenType.BEARER;

/**
 * 恰要求处理工具
 */
public class AuthorizationRequestTool {

    public static Mono<String> extractHeaderToken(String value) {
        if ((value.toLowerCase().startsWith(BEARER.getValue().toLowerCase()))) {
            String authHeaderValue = value.substring(BEARER.getValue().length()).trim();
            // Add this here for the auth details later. Would be better to change the signature of this method.
            int commaIndex = authHeaderValue.indexOf(',');
            if (commaIndex > 0) {
                authHeaderValue = authHeaderValue.substring(0, commaIndex);
            }
            return Mono.just(authHeaderValue);
        }
        return Mono.empty();
    }


}
